﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace InnovTech.Util.Workflow
{
    public abstract class WorkflowStepBase
    {
        public EventHandler Started;
        public EventHandler Finished;

        public WorkflowStepBase(EventHandler started, EventHandler finished)
        {
            if (started == null)
                Started = started;
            if (finished == null)
                Finished = finished;
        }

        public WorkflowStepBase()
        {
            Started = (sender, args) => { };
            Finished = (sender, args) => { };
        }

        public void Run()
        {
            Started(this, EventArgs.Empty);

            Execute();

            Finished(this, EventArgs.Empty);
        }

        protected abstract void Execute();
    }

    public class WorkflowStep : WorkflowStepBase
    {
        protected Action _action;
        public WorkflowStep(Action act, EventHandler started = null, EventHandler finished = null)
            : base(started, finished)
        {
            _action = act;
        }

        protected override void Execute()
        {
            _action();
        }
    }
}
